﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Configuration;
using System.Net.Configuration;
using System.Net.Mail;
using System.Web.Configuration;
using System.Text;

namespace ankietyzacja.Logic
{
    public class AnkietyzacjaSmtpClient
    {

    


     public void sendEmail(String subject, String content, String to, Boolean html)
        {

            Configuration config = WebConfigurationManager.OpenWebConfiguration(HttpContext.Current.Request.ApplicationPath);
            MailSettingsSectionGroup settings = (MailSettingsSectionGroup)config.GetSectionGroup("system.net/mailSettings");

            MailMessage mail = new MailMessage();
            mail.Body = content;
            mail.IsBodyHtml = html;
            mail.To.Add(new MailAddress(to));
            mail.From = new MailAddress(settings.Smtp.From, "System ankietyzacji", Encoding.UTF8);
            mail.Subject = subject;
            mail.SubjectEncoding = Encoding.UTF8;
            mail.Priority = MailPriority.Normal;

            SmtpClient smtp = new SmtpClient();
            smtp.Credentials = new System.Net.NetworkCredential(settings.Smtp.Network.UserName, settings.Smtp.Network.Password);
            smtp.Host = settings.Smtp.Network.Host;
            smtp.Port = settings.Smtp.Network.Port;
            smtp.Send(mail);
        }


    public void newUserEmail(String userName, String password, String email) {

             String tresc =
                    @"Utworzono nowego użytkownika.
Proszę zalogować się do systemu za pomocą poniższych danych:
Nazwa użytkownika: " + userName + @" 
Hasło: " + password;

            AnkietyzacjaSmtpClient smtpClient = new AnkietyzacjaSmtpClient();
            sendEmail("Nowy użytkownik", tresc, email, false);

    }

    }

}